<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>

<body>
<div id="output">
	
</div>
	<script type="text/javascript">
	var r = new Array(1,2,3,4,5,6,7,8,9);
	var gamecell = new Array(82);
	gamecell[0]=0;
	
	for (i = 1; i <= 81; i++) {
		gamecell[i] = 0;
	}
	
	j = 1;
	for(i=r.length-1 ; i>=0  ;i--)
	{	
		pos = Math.floor(Math.random()* i );
		gamecell[j++] = r[pos];
		
		t = r[pos];
		r[pos] = r[i];
		r[i] = t;
	}
	ff(10);
	function ff( pos )
	{
		var i;
		for(i=1;i<=9;i++)
		{
			gamecell[pos] = i;
			if(validateCell(pos))
			{
				ff(pos+1);
			}
		}
		if(pos >18)
			return true;
	}
	
	function validateCell( pos )
	{
		var i;
		var cell = gamecell[pos];
		var row = pos%9==0?parseInt(pos / 9):parseInt(pos / 9)+ 1;
		var col = pos%9==0?9:pos%9;
		for(i=1;i<=9;i++)
		{
			if((gamecell[(row-1)*9+i] == cell) && ((row-1)*9+i != pos) )
				return false;
			if((gamecell[(i-1)*9+col] == cell) && ((i-1)*9+col != pos) )
				return false;
		}
		return true;
	}
	
	
	output(gamecell);
	function output( gamecell )
	{	
		var i,j;
		for (i = 1; i <= 81; i++) {
			if(i%9==0)
				document.getElementById('output').innerHTML += gamecell[i] + "<br />";
			else
				document.getElementById('output').innerHTML += gamecell[i] + " ";
		}
	}
</script>
</body>
</html>